package com.cutefool.zero.code.sso;

import com.cutefool.zero.code.sso.config.Oauth2Configuration;
import com.cutefool.zero.code.sso.consts.SsoConsts;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LoginController {

    @Resource
    private Oauth2Configuration oauth2Configuration;

    @GetMapping("/doLogin")
    public String doLogin(@RequestParam(name = "redirect_uri") String redirect_uri, @RequestParam(name = "state", required = false, defaultValue = "state") String state) {
        return "redirect:" + String.format(SsoConsts.AUTHORIZATION_URI, oauth2Configuration.getDomain(), redirect_uri, oauth2Configuration.getClientId(), state, "scope");
    }
}
